package com.zhl.jdk8_time3;

import java.time.Clock;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Set;

public class Test_ZoneId_ZoneIDateTime {
    public static void main(String[] args) {
        //目标：了解时区和带时区的时间
        //1.ZoneId的常见方法
        //pibluc static ZoneId systemDefault(); 返回默认时区
        ZoneId zoneId = ZoneId.systemDefault();
        System.out.println(zoneId.getId());
        System.out.println(zoneId);

        //获取java支持的全部时区Id  public static Set<String> getAvailableZoneIds()
        Set<String> zoneIds = ZoneId.getAvailableZoneIds();
        System.out.println(zoneIds);

        //把某个时区的Id转换为ZoneId对象
        ZoneId zoneId1 = ZoneId.of("Asia/Shanghai");
        System.out.println(zoneId1);

        //2.带时区的时间
        //public static ZonedDateTime now(ZoneId zone);  获取某个时区的当前时间
        ZoneId zoneId2 = ZoneId.of("America/New_York");
        ZonedDateTime now1 = ZonedDateTime.now(zoneId2);
        ZonedDateTime now2 = ZonedDateTime.now(zoneId1);

        System.out.println(now1);
        System.out.println(now2);

        //世界标准时间
        ZonedDateTime utc = ZonedDateTime.now(Clock.systemUTC());
        System.out.println(utc);

        //public static ZonedDateTime now(); 获取当前时间，默认时区
        ZonedDateTime now3 = ZonedDateTime.now();
        System.out.println(now3);
    }
}
